package 计数法.第一个唯一字符;

/**
 * TODO
 *
 * @className: dygwyzf
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-04 15:38
 **/
public class dygwyzf {
    public static void main(String[] args) {
        String s = "loveleetcode";
        System.out.println(firstUniqChar(s));
    }
    public static int firstUniqChar(String s) {
        int[] arr = new int[26];
        for (int i = 0; i < s.length(); i++) {
            int charIndex = (int)s.charAt(i) - 97;
            ++arr[charIndex];
        }
        for (int i = 0; i < s.length(); i++) {
            int charIndex = (int)s.charAt(i) - 97;
            if (arr[charIndex]==1){
                return i;
            }
        }
        return -1;
    }
}
